from django.views.generic import ListView
from django.contrib.auth.models import Permission
from dashboard.common.utiles import get_pagerange

import logging
logger = logging.getLogger("myself")

class PermissionListView(ListView):
    model = Permission
    template_name = "permissionlist.html"
    paginate_by = 10
    ordering = "id"

    # 自定义变量，显示的前后分页数量
    before_range_num = 4
    after_range_num = 4


    def get_queryset(self):
        queryset = super(PermissionListView, self).get_queryset()
        #
        # username = self.request.GET.get("search_username", None)
        # if username:
        #     queryset = queryset.filter(username__icontains=username)
        return queryset

    def get_context_data(self, **kwargs):
        context = super(PermissionListView, self).get_context_data(**kwargs)
        context['page_range'] = get_pagerange(context['page_obj'],self.before_range_num,self.after_range_num)
        context['search_data']=""
        logger.debug(context)
        return context

